﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Moving03
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        private int idnoiden;
        private int idduongdi;
        public int secsion_id_User_Dangnhap = 2;/// Nhờ anh Trí gán dùm id_dangnhap vô chổ này nhé!
        protected void Page_Load()
        {
            thongbao.Visible = false;
            lbl_Visible_false();
            if (secsion_id_User_Dangnhap != 0)
            {
                lbl_Visible_True();
                ThongTinVanChuyen(secsion_id_User_Dangnhap);
            }
            else
            {
                thongbao.Visible = true;
                lbl_Visible_false();
                thongbao.InnerHtml = " <script type='text/javascript'>window.alert('Bạn chưa đăng nhập hoặc bạn chưa có thông tin gói hàng nào!')</script>";
            }
        }
        public void ThongTinVanChuyen(int id_User_DangNhap)
        {
            var query = from ttvc in context.ThongTinVanChuyens
                        join user in context.Users on ttvc.Id_User equals user.Id_User
                        where user.Id_User == id_User_DangNhap
                        select new { ttvc.Id_TTVC,ttvc.Id_User, ttvc.Id_LoaiHang, ttvc.Id_LoHang };
            foreach (var i in query)
            {
                var query2 = from lohang in context.LoHangs
                             where lohang.Id_LoHang == i.Id_LoHang
                             select new { lohang.Ten_lo_hang, lohang.Trong_luong, lohang.Gia_tri, lohang.So_goi, lohang.Giong_nhau };
                foreach (var j in query2)
                {
                    lbl_tenlohang.Text = j.Ten_lo_hang;
                    lbl_trongluong.Text = j.Trong_luong.ToString() + " kg";
                    lbl_giatri.Text = j.Gia_tri.ToString() + " $";
                    lbl_sogoi.Text = j.So_goi.ToString();
                    int giongnhau = int.Parse(j.Giong_nhau.ToString());
                    if (giongnhau == 1)
                    {
                        lbl_giongnhau.Text = "Giống nhau";
                    }
                    else
                        lbl_giongnhau.Text = "Không giống nhau";
                }
            }
            var query1 = from us in context.Users
                         join nd in context.NoiDens on us.Id_User equals id_User_DangNhap
                         where us.ID_Noiden == nd.Id_NoiDen
                         select new { nd.Id_NoiDen, nd.Id_Quocgia, nd.Mabuudien, nd.Nguoinhan, nd.Nharieng, nd.Thanhpho, nd.Email, nd.Dienthoai, nd.Diachi };
            foreach (var i in query1)
            {
                idnoiden = int.Parse(i.Id_NoiDen.ToString());
                lbl_nguoinhan.Text = i.Nguoinhan;
                var query2 = from quocgia in context.DanhSachQuocGias
                             where quocgia.Id_MaQGia == i.Id_Quocgia
                             select new { quocgia.TenQuocGia };
                foreach (var j in query2)
                {
                    lbl_quocgianguoinhan.Text = j.TenQuocGia;
                }
                lbl_diachinguoinhan.Text = i.Diachi;
                lbl_thanhphonguoinhan.Text = i.Thanhpho;
                lbl_mabuudiennguoinhan.Text = i.Mabuudien.ToString();
                lbl_emailnguoinhan.Text = i.Email;
                lbl_dienthoainguoinhan.Text = i.Dienthoai;
                lbl_diachinguoinhan.Text = i.Diachi;
                lbl_nhariengnguoinhan.Text = i.Nharieng;
            }
            var query3 = from ndi in context.NoiDis
                         join dd in context.DuongDis on ndi.Id_Noidi equals dd.Id_NoiDi
                         where dd.Id_NoiDen == idnoiden
                         select new { ndi.Id_Noidi, ndi.NguoiGoi, ndi.Id_Quocgia, ndi.Mabuudien, ndi.Nharieng, ndi.Thanhpho, ndi.Email, ndi.Diachi, ndi.Dienthoai, dd.Id_DuongDi };
            foreach (var i in query3)
            {
                lbl_nguoigoi.Text = i.NguoiGoi;
                var query5 = from quocgia in context.DanhSachQuocGias
                             where quocgia.Id_MaQGia == i.Id_Quocgia
                             select new { quocgia.TenQuocGia };
                foreach (var j in query5)
                {
                    lbl_quocgianguoigoi.Text = j.TenQuocGia;
                }
                lbl_mabuudiennguoigoi.Text = i.Mabuudien.ToString();
                lbl_dienthoainguoigoi.Text = i.Dienthoai.ToString();
                lbl_dcnguoigoi.Text = i.Diachi;
                lbl_tpnguoigoi.Text = i.Thanhpho;
                lbl_nhariengnguoigoi.Text = i.Nharieng;
                lbl_emailnguoigoi.Text = i.Email;
                //lbl_ngaybatdaugoi.Text = i.NgayBatDau.ToString();
                idduongdi = int.Parse(i.Id_DuongDi.ToString());
            }

            var qurey6 = from ddcn in context.DiaDiemCapNhats
                         join ddtg in context.DiaDiemTrungGians on ddcn.Id_DDTrungGian equals ddtg.Id_DDTrungGian
                         where ddcn.Id_DuongDi == idduongdi
                         select new { ddcn.NgayToi, ddtg.TenDiaDiem};
            foreach (var i in qurey6)
            {
                lbl_ngaydukien.Text = i.NgayToi.ToString();
                lbl_diadiemhientaihangden.Text = i.TenDiaDiem;
            }
        }
        public void lbl_Visible_false()
        {
            lbl1.Visible = false;
            lbl2.Visible = false;
            lbl3.Visible = false;
            lbl4.Visible = false;
            lbl5.Visible = false;
            lbl6.Visible = false;
            lbl7.Visible = false;
            lbl8.Visible = false;
            lbl9.Visible = false;
            lbl10.Visible = false;
            lbl11.Visible = false;
            lbl12.Visible = false;
            lbl13.Visible = false;
            lbl14.Visible = false;
            lbl15.Visible = false;
            lbl16.Visible = false;
            lbl17.Visible = false;
            lbl18.Visible = false;
            lbl19.Visible = false;
            lbl20.Visible = false;
            lbl21.Visible = false;
            lbl22.Visible = false;
            lbl23.Visible = false;
            lbl24.Visible = false;
            lbl25.Visible = false;
            lbl26.Visible = false;
            lbl27.Visible = false;
        }
        public void lbl_Visible_True()
        {
            lbl1.Visible = true;
            lbl2.Visible = true;
            lbl3.Visible = true;
            lbl4.Visible = true;
            lbl5.Visible = true;
            lbl6.Visible = true;
            lbl7.Visible = true;
            lbl8.Visible = true;
            lbl9.Visible = true;
            lbl10.Visible = true;
            lbl11.Visible = true;
            lbl12.Visible = true;
            lbl13.Visible = true;
            lbl14.Visible = true;
            lbl15.Visible = true;
            lbl16.Visible = true;
            lbl17.Visible = true;
            lbl18.Visible = true;
            lbl19.Visible = true;
            lbl20.Visible = true;
            lbl21.Visible = true;
            lbl22.Visible = true;
            lbl23.Visible = true;
            lbl24.Visible = true;
            lbl25.Visible = true;
            lbl26.Visible = true;
            lbl27.Visible = true;
        }
    }
}